package com.jinyu.admin.service.sys.impl;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.jinyu.admin.service.sys.SysMenuService;
import com.jinyu.dao.entity.sys.SysMenu;
import com.jinyu.dao.mapper.sys.SysMenuMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Author: yangli
 * @Despriction:
 * @Package: com.jinyu.admin.service.sys.impl
 * @Date:Created in 2022/5/7 22:06
 * @Modify By:
 */
@Service
public class SysMenuServiceImpl implements SysMenuService {

    @Autowired
    private SysMenuMapper sysMenuMapper;

    @Override
    public int insert(SysMenu sysMenu) {
        StpUtil.checkLogin();
        String loginId = StpUtil.getLoginIdAsString();
        sysMenu.setId(IdUtil.getSnowflakeNextId());
        sysMenu.setCreateUser(loginId);
        sysMenu.setUpdateUser(loginId);
        if (StrUtil.isBlank(sysMenu.getPid())) sysMenu.setPid("0000");
        return sysMenuMapper.insert(sysMenu);
    }

    @Override
    public int delete(long id) {
        return sysMenuMapper.delete(id);
    }

    @Override
    public int update(SysMenu sysMenu) {
        return sysMenuMapper.update(sysMenu);
    }

    @Override
    public SysMenu selectByOne(long id) {
        return sysMenuMapper.selectByOne(id);
    }

    @Override
    public List<SysMenu> pageList(int offset, int pagesize) {
        return sysMenuMapper.pageList(offset,pagesize);
    }
}
